package com.zyx.jsonpath.runner;

import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.EnumSet;
import java.util.Set;

/**
 * <p>初始化JsonPath的InitJsonProvider
 *
 * @author Yaxi.Zhang
 * @since 2022/12/8 08:37
 */
@Component
public class InitJsonProvider implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        Configuration.setDefaults(new Configuration.Defaults() {
            private final JsonProvider jsonProvider = new JacksonJsonProvider();
            private final MappingProvider mappingProvider = new JacksonMappingProvider();
            @Override
            public JsonProvider jsonProvider() {
                return jsonProvider;
            }
            @Override
            public MappingProvider mappingProvider() {
                return mappingProvider;
            }
            @Override
            public Set<Option> options() {
                return EnumSet.noneOf(Option.class);
            }
        });
    }

}
